package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.Manifest;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.ui.broadcast.SMSReceiver;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by TCL on 2019/9/17.
 * Describe:
 */
public class SMSActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_permission)
    TextView tvPermission;
    @BindView(R.id.tv_sms)
    TextView tvSms;

    private SMSReceiver myReceiver;
    private IntentFilter intentFilter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sms;
    }

    @Override
    protected void initData() {
        myReceiver = new SMSReceiver();
        intentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_sms));

    }

    @OnClick(R.id.btn_permission)
    public void onViewClicked() {
        requestPermission(6,
                new String[]{Manifest.permission.RECEIVE_SMS, Manifest.permission.READ_SMS},
                new Runnable() {
                    @Override
                    public void run() {
                        tvPermission.setText("已经获取权限");
                    }
                },
                new Runnable() {
                    @Override
                    public void run() {
                        tvPermission.setText("暂未获取权限");
                    }
                });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerReceiver(myReceiver, intentFilter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myReceiver);
    }
}
